package jmu.cultural_tourism.controller;

import jmu.cultural_tourism.service.AttractionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/attractions")
public class AttractionController {

    private final AttractionService attractionService;

    @Autowired
    public AttractionController(AttractionService attractionService) {
        this.attractionService = attractionService;
    }


    @GetMapping("/location")
    public Map<String, Double> getCurrentLocation() {
        return attractionService.getCurrentLocation();
    }


    @GetMapping("/introduction")
    public Map<String, String> getAttractionIntroduction(
            @RequestParam(required = false) Double latitude,
            @RequestParam(required = false) Double longitude) {

        if (latitude == null || longitude == null) {
            Map<String, Double> location = attractionService.getCurrentLocation();
            latitude = location.get("latitude");
            longitude = location.get("longitude");
        }

        String introduction = attractionService.generateAttractionIntroduction(latitude, longitude);

        Map<String, String> response = new HashMap<>();
        response.put("introduction", introduction);

        return response;
    }

    @GetMapping("/by-city")
    public Map<String, String> getAttractionsByCity(@RequestParam String city) {
        String introduction = attractionService.generateAttractionByCity(city);

        Map<String, String> response = new HashMap<>();
        response.put("introduction", introduction);

        return response;
    }

}

